package com.intellagric.agriecom.controller.agriecom_index;

import com.intellagric.agriecom.module.agriecom_news.NewsService;
import com.intellagric.module.agriecom.agriecom_news.NewsVo;
import com.intellagric.pojo.AgriecomNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
/**
 * @Autuor cky
 * @description
 * @Date 14:58 2019/2/24
 */
@Controller
public class NewsInfoController {
    @Autowired
    public NewsService newsService;
    /**
     * 热门新闻 按照阅读量、点赞数和时间
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/agriecomIndex/newsInfo/hotNews")
    @ResponseBody
    public List<AgriecomNews> hotNews(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "5") int rows){
        NewsVo vo=new NewsVo();
        vo.setThumbsUpCount(true);
        vo.setReadCount(true);
        vo.setCreateDate(true);
        return newsService.getHotListByVo(page,rows,vo).getData();
    }

    /**
     * 成功案例 按照点赞数和时间
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/agriecomIndex/newsInfo/successExample")
    @ResponseBody
    public List<AgriecomNews> successExample(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "5")int rows){
        NewsVo vo=new NewsVo();
        vo.setThumbsUpCount(true);
        vo.setCreateDate(true);
        return newsService.getHotListByVo(page,rows,vo).getData();
    }

    /**
     * 获取评论数最多的资讯
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/agriecomIndex/newsInfo/discussion")
    @ResponseBody
    public List<AgriecomNews> discussion(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "5")int rows){
        NewsVo vo=new NewsVo();
        vo.setCommentCount(true);
        vo.setCreateDate(true);
        return newsService.getHotListByVo(page,rows,vo).getData();
    }

    /**
     * 热门且近期新闻
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/agriecomIndex/newsInfo/latestNews")
    @ResponseBody
    public List<AgriecomNews> latestNews(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "5")int rows){
        NewsVo vo=new NewsVo();
        vo.setCreateDate(true);
        return newsService.getHotListByVo(page,rows,vo).getData();
    }

    /**
     * 只按时间排序，获取最新
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/agriecom/news/mostLatestNews")
    @ResponseBody
    public List<AgriecomNews> mostLatestNews(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "5")int limit){
        return newsService.getLatestNews(page,limit);
    }

    /**
     * 根据数据库顺序随机获取列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/agriecom/news/list")
    @ResponseBody
    public List<AgriecomNews> list(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value="limit",defaultValue = "10")int limit){
        return newsService.getList(page,limit).getData();
    }

    /**
     * 转发
     * @return
     */
    @RequestMapping("/ariecom/news/forward")
    public String forward(){
        return "redirect:/news.html";
    }

}
